package cn.tan.database.jdbc;

import java.sql.*;
@SuppressWarnings({"Duplicates", "unused", "SqlNoDataSourceInspection", "SqlDialectInspection"})
public class DBUtil {
    private static final String URL = "jdbc:h2:D:/sample;MODE=MYSQL;DB_CLOSE_DELAY=-1";


    private static final String NAME = "sa";
    private static final String PASSWORD = "sa";

    public static Connection getConnection() throws SQLException {
         Connection conn = DriverManager.getConnection(URL, NAME, PASSWORD);
         return conn;
    }
    /*
    public static void main(String[] args) throws SQLException {
        try (Connection conn = DriverManager.getConnection(URL, NAME, PASSWORD)) {
            Statement stmt = conn.createStatement();
            stmt.executeUpdate(
                    "insert into `student` (`id`,`name`,`email`,`phone`,`sex`) values ('Jerry', 27);" +
                            "insert into `user` (`name`,`age`) values ('Angel', 25);"
            );

            ResultSet rs = stmt.executeQuery("select * from user");//选择import java.sql.ResultSet;

            // 遍历每行记录
            while (rs.next()) {
                //如果结果集中有数据，就会循环打印出来
                System.out.println(rs.getString("id") + "," + rs.getString("name") + "," + rs.getInt("age"));
            }

        } catch (SQLException e) {
            e.printStackTrace();
        }
    }*/
}
